// 数据层
import request from '@/utils/request.js'
import axios from 'axios'

// 获取验证码
export function getSMcode (mobile) {
  return request({
    url: 'sms/codes/' + mobile
  })
}

export function userLogin (form) {
  return request({
    url: 'authorizations',
    method: 'POST',
    data: form
  })
}

// 获取当前用户的信息
export function getUserInfo () {
  return request({
    url: '/user'
  })
}

/**
 * 获取当前用户的资料
 */
export const getUserProfile = () => {
  return request({ url: '/user/profile' })
}

/**
 * 修改头像
 * @param {Object} formData -  {photo:'文件数据'}
 */

export const updateUserPhoto = (formData) => {
  return request({
    url: '/user/photo',
    method: 'patch',
    data: formData
  })
}

/**
 * 修改用户
 * @param {Object} user - 用户对象
 */
export const updateUser = (user) => {
  return request({
    url: '/user/profile',
    method: 'patch',
    data: user
  })
}

/**
 * 刷新token
 * @param {String} refreshToken - 保存的refresh_token
 * @returns
 */
export const refreshTokenAPI = (refreshToken) => {
  return axios({
    url: 'http://101.35.25.8:8000/v1_0/authorizations',
    method: 'put',
    headers: {
      Authorization: `Bearer ${refreshToken}`
    }
  })
}
